<?php
/**
 * Magento Enterprise Edition
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Magento Enterprise Edition End User License Agreement
 * that is bundled with this package in the file LICENSE_EE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.magento.com/license/enterprise-edition
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     default_default
 * @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license http://www.magento.com/license/enterprise-edition
 */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>">
<head>
<?php echo $this->getChildHtml('head') ?>
<style type="text/css">
html,body { height:100%; }
</style>
</head>
<body id="html-body"<?php echo $this->getBodyClass()?'class="'.$this->getBodyClass().'"':'' ?>>
<div id="cms-revision-preview" class="cms-revision-preview">
    <div class="toolbar">
        <?php echo $this->getChildHtml('tools') ?>
    </div>
<iframe name="preview_iframe" id="preview_iframe" frameborder="0"></iframe>
<?php echo $this->getChildHtml('preview_form') ?>
</div>
<div id="loading-mask" style="display:none">
    <p class="loader" id="loading_mask_loader"><img src="<?php echo $this->getSkinUrl('images/ajax-loader-tr.gif') ?>" alt="<?php echo Mage::helper('core')->quoteEscape(Mage::helper('adminhtml')->__('Loading...')) ?>"/><br/><?php echo Mage::helper('adminhtml')->__('Please wait...') ?></p>
</div>
<script type="text/javascript">
//<![CDATA[
    var previewForm = $('preview_form');
    var loadingMask = $('loading-mask');
    var previewIframe = $('preview_iframe');

    var publishUrlTemplate = '<?php echo $this->getUrl('*/*/publish', array('revision_id' => '{{value}}'))?>';
    var publishUrl = '';

    function preview() {
        previewForm.writeAttribute('target', previewIframe.readAttribute('id'));
        blockPreview();
        previewForm.submit();
    }

    function blockPreview() {
        var cumulativeOffset = $('cms-revision-preview').cumulativeOffset();

        $('loading-mask').setStyle({
            top:  ( cumulativeOffset.top ) + 'px',
            left: ( cumulativeOffset.left ) + 'px',
            width: $('cms-revision-preview').getWidth() + 'px',
            height: $('cms-revision-preview').getHeight() + 'px'
        });

        toggleSelectsUnderBlock($('loading-mask'), false);
        Element.show('loading-mask');
        setLoaderPosition();
    }

    function unBlockPreview() {
        toggleSelectsUnderBlock(loadingMask, true);
        Element.hide(loadingMask);
    }

    Event.observe(window, 'load', preview);
    Event.observe(previewIframe, 'load', unBlockPreview);

    function togglePublish(state) {
        var button = $('preview-buttons-publish');
        if (button) {
            if (state) {
                button.show();
                publishUrl = publishUrlTemplate.replace('{{value}}', state);
            } else {
                button.hide();
            }
        }
    }

    togglePublish(false);

    function publish() {
        setLocation(publishUrl);
    }

//]]>
</script>
</body>
</html>
